PROCEDURE TForm4.TestShlWAPIStrFormatByteSize64A(Sender : TObject);
VAR filehandle : HFILE;
VAR sizetoformat : LARGE_INTEGER;
VAR totalbytes : LONGLONG;
VAR bytesavailable : LONGLONG;
VAR sizestrbufp : PChar;
VAR bufsize : UINT;
VAR apiretpointer : PChar;
VAR newinfoline : STRING;
BEGIN
filehandle := 0;
FillChar(sizetoformat, SizeOf(sizetoformat), #0);
FillChar(totalbytes, SizeOf(totalbytes), #0);
FillChar(bytesavailable, SizeOf(bytesavailable), #0);
sizestrbufp := NIL;
bufsize := 0;
apiretpointer := NIL;
newinfoline := '';
//Format as byte
newinfoline := 'StrFormatByteSize64A called with ' + IntToStr(Int64(sizetoformat));
Memo1.Lines.Add(newinfoline);
sizestrbufp := StrAlloc(64);
bufsize := StrBufSize(sizestrbufp);
apiretpointer := StrFormatByteSize64A(LONGLONG(sizetoformat), sizestrbufp, bufsize);
newinfoline := apiretpointer;
Memo1.Lines.Add(newinfoline);
StrDispose(sizestrbufp);
//Format as KByte
sizetoformat.LowPart := 12345;
newinfoline := 'StrFormatByteSize64A called with ' + IntToStr(Int64(sizetoformat));
Memo1.Lines.Add(newinfoline);
sizestrbufp := StrAlloc(64);
bufsize := StrBufSize(sizestrbufp);
apiretpointer := StrFormatByteSize64A(LONGLONG(sizetoformat), sizestrbufp, bufsize);
newinfoline := apiretpointer;
Memo1.Lines.Add(newinfoline);
StrDispose(sizestrbufp);
//Format as MByte
filehandle := CreateFile('C:\Windows\System32\Shell32.dll', GENERIC_READ, FILE_SHARE_READ OR FILE_SHARE_WRITE, NIL,
OPEN_EXISTING, 0, 0);
sizetoformat.LowPart := GetFileSize(filehandle, @sizetoformat.HighPart);
newinfoline := 'StrFormatByteSize64A called with ' + IntToStr(Int64(sizetoformat));
Memo1.Lines.Add(newinfoline);
sizestrbufp := StrAlloc(64);
bufsize := StrBufSize(sizestrbufp);
apiretpointer := StrFormatByteSize64A(LONGLONG(sizetoformat), sizestrbufp, bufsize);
newinfoline := apiretpointer;
Memo1.Lines.Add(newinfoline);
StrDispose(sizestrbufp);
CloseHandle(filehandle);
//Format as GByte
FillChar(sizetoformat, SizeOf(sizetoformat), #0);
GetDiskFreeSpaceEx('E:\', TLargeInteger(sizetoformat), totalbytes, @bytesavailable);
newinfoline := 'StrFormatByteSize64A called with ' + IntToStr(Int64(sizetoformat));
Memo1.Lines.Add(newinfoline);
sizestrbufp := StrAlloc(64);
bufsize := StrBufSize(sizestrbufp);
apiretpointer := StrFormatByteSize64A(LONGLONG(sizetoformat), sizestrbufp, bufsize);
newinfoline := apiretpointer;
Memo1.Lines.Add(newinfoline);
newinfoline := '';
newinfoline := 'StrFormatByteSize64A called with ' + IntToStr(Int64(totalbytes));
Memo1.Lines.Add(newinfoline);
apiretpointer := StrFormatByteSize64A(totalbytes, sizestrbufp, bufsize);
newinfoline := apiretpointer;
Memo1.Lines.Add(newinfoline);
newinfoline := '';
newinfoline := '';
newinfoline := 'StrFormatByteSize64A called with ' + IntToStr(Int64(bytesavailable));
Memo1.Lines.Add(newinfoline);
apiretpointer := StrFormatByteSize64A(bytesavailable, sizestrbufp, bufsize);
newinfoline := apiretpointer;
Memo1.Lines.Add(newinfoline);
StrDispose(sizestrbufp);
Memo1.Lines.Add('');
END; |